#ifndef __GD32E23x_HAL_RS485_H__
#define __GD32E23x_HAL_RS485_H__

#include <stdint.h>

//#define RS485_BAUDRATE					9600
#define RS485_BAUDRATE			    115200U
//#define RS485_BAUDRATE			    38400U
//#define RS485_BAUDRATE					19200U

#define RS485_TXBUFFER_SIZE				32
#define RS485_RXBUFFER_SIZE				16

#define RS485_HALF_RX_BUFFER_SIZE	    8

#define RS485_TXFIFO_SIZE                 64
#define RS485_RXFIFO_SIZE                 64

#define RS485_UART_IO_RCU         RCC_AHBPeriph_GPIOA
#define RS485_UART_IO_BASE        GPIOA

#define RS485_UART_TX_PIN         GPIO_Pin_2
#define RS485_UART_RX_PIN         GPIO_Pin_3

#define RS485_RX_PIN_SOURCE       GPIO_PinSource3
#define RS485_TX_PIN_SOURCE       GPIO_PinSource2

#define RS485_UART_RCU            RCC_APB1Periph_UART2
#define RS485_UART_CORE           UART2

#define RS485_DMA_TX_CHANNEL      DMA_Channel4
#define RS485_DMA_RX_CHANNEL      DMA_Channel5

typedef struct {
    void (*init)(void);         //初始化
    uint16_t (*write)(void *buf, uint16_t len);     //数据写
    uint16_t (*read) (void *buf, uint16_t len);     //数据读
	void (*tprint)(const char *format, ...);        //格式化打印
}rs485_t;

extern void UART2_IRQHandler(void);

extern const rs485_t g_rs485_;

#endif//__GD32E23x_HAL_RS485_H__
